home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 051-075 / disk_071 / pwdemo / example.asm < prev    next >
Assembly Source File  |  1992-05-06  |  5KB  |  172 lines

  1. ;  EXAMPLE.ASM written 09/15/86 by Martin Murray
  2.  
  3. ********************************************************************************
  4. *       THIS CODE IS IN NO WAY COPYRIGHT 1986 BY INOVATRONICS, INC.  IN FACT,  *
  5. *       YOU CAN DO ANYTHING WITH IT THAT YOU WANT TO DO.  JUST REMEMBER,       *
  6. *       INOVATRONICS, INC. WILL BEAR ABSOLUTELY NO RESPONSIBILITY FOR THE USE, *
  7. *       MISUSE, INABILITY TO USE OR INABLITY TO UNDERSTAND ANY OR ALL PARTS OF *
  8. *       THIS CODE.  ENJOY IT IN GOOD HEALTH.                                   *
  9. ********************************************************************************
  10. ********************************************************************************
  11. *       THE PURPOSE OF THE CODE IS TO LET YOU SEE WHAT YOUR PowerWindows       *
  12. *       GENERATED SOURCE CODE WILL LOOK LIKE IN A PROGRAM.  IN MOST CASES, ALL *
  13. *       YOU SHOULD HAVE TO DO IS ASSEMBLE THIS FILE.  IT WILL  AUTOMATICALLY   *
  14. *       INCLUDE YOUR SOURCE FILE, PROVIDED IT IS IN THE DEFAULT DIRECTORY, AND *
  15. *       IS NAMED "example.i".  JUST ASSEMBLE IT, LINK IT AND RUN IT.  IT       *
  16. *       DEFAULTS TO TERMINATING WHEN THE CLOSE GADGET IS HIT, BUT IF YOU LOOK  *
  17. *       BELOW YOU'LL SEE HOW TO MAKE IT TERMINATE ON ANY EVENT AT ALL.         *
  18. ********************************************************************************
  19.  
  20.     include "exec/types.i"
  21.     include "exec/io.i"
  22.     include "exec/strings.i"
  23.     include "libraries/dosextens.i"
  24.     include "intuition/intuition.i"
  25.  
  26.     xref    _AbsExecBase
  27.  
  28. ************    EQUATES
  29. NULL    equ    0
  30.  
  31. ************    MACROS
  32. xlib    macro
  33.     xref    _LVO\1
  34.     endm
  35.  
  36. callsys    macro    (routine name to call, A6 must have base pointer of library)
  37.     xlib    \1
  38.     CALLLIB    _LVO\1
  39.     endm
  40.  
  41. call    macro    (address to call)
  42.     bsr    \1
  43.     endm
  44.  
  45. push    macro    (long ea to push)
  46.     move.l    \1,-(sp)
  47.     endm
  48.  
  49. pull    macro    (long ea to fetch without popping)
  50.     move.l    (sp),\1
  51.     endm
  52.  
  53. pop    macro    (long ea to pop into)
  54.     move.l    (sp)+,\1
  55.     endm
  56.  
  57.  
  58. *********    DATA AREA
  59.     DATA
  60. Intuitionname:    string <'intuition.library'>
  61. InitialSP:    dc.l    0
  62. MeMyselfandI:    dc.l    0
  63. ReturnMsg:    dc.l    0
  64. _IntuitionBase:    dc.l    0
  65. CurrentWindow:    dc.l    0
  66.     include "example.i"        ;include the PowerWindows code
  67.  
  68.  
  69. ************    PROGRAM START
  70.     CODE
  71. ;Intitialize by saving the stack pointer and finding our own task.
  72.     move.l    sp,InitialSP        ;save the stack pointer
  73.     move.l    _AbsExecBase,a6        ;get the system library address
  74.     sub.l    a1,a1
  75.     callsys    FindTask        ;please, I must find myself
  76.     move.l    d0,MeMyselfandI        ;save the address of the TCB list node
  77.     move.l    d0,a0            ;  in case we need it for some reason
  78.     tst.l    PR_CLI(a0)        ;were we run by Workbench?
  79.     bne    1$            ;no-jump
  80.     lea    PR_MSGPORT(a0),a0    ;wait for the startup message
  81.     push    a0
  82.     callsys    WaitPort
  83.     pop    a0            ;get it
  84.     callsys    GetMsg
  85.     move.l    d0,ReturnMsg        ;save the message
  86. 1$:
  87.     moveq    #0,d0            ;open intuition.library
  88.     lea    Intuitionname,a1
  89.     callsys    OpenLibrary
  90.     move.l    d0,_IntuitionBase    ;save her address
  91.     beq    FatalExit        ;quit NOW if no Intuition
  92.     move.l    d0,a6            ;A6 gets the pointer until we call Exec
  93.  
  94. main:
  95. ;do the opening of the window, et all.
  96.     lea    NewWindowStructure,a0    ;point to the NewWindow structure and
  97.     callsys    OpenWindow        ;  open the window (gadgets will come up
  98.     move.l    d0,CurrentWindow    ;  too.)
  99.     beq    Exit            ;leave if couldn't open window
  100.  
  101. ;attach the menu if present
  102.     ifd MenuList
  103.     move.l    d0,a0            ;window address to A0
  104.     lea    MenuList,a1        ;menustrip pointed to by A1
  105.     callsys    SetMenuStrip
  106.     endc
  107.  
  108. ;draw the IntuiText only if there is some
  109.     ifd IntuiTextList
  110.     move.l    CurrentWindow,a0    ;get the RastPort address
  111.     move.l    WD_RPORT(a0),a0
  112.     lea    IntuiTextList,a1    ;print this list of IText structures
  113.     moveq    #0,d0            ;let the text position itself
  114.     move.l    d0,d1
  115.     callsys    PrintIText
  116.     endc
  117.  
  118. ;draw the Borders only if there are some of them
  119.     ifd BorderList
  120.     move.l    CurrentWindow,a0    ;get the RastPort address
  121.     move.l    WD_RPORT(a0),a0
  122.     lea    BorderList,a1        ;draw this list of Border structures
  123.     moveq    #0,d0            ;let the borders position themselves
  124.     move.l    d0,d1
  125.     callsys    DrawBorder
  126.     endc
  127.  
  128. ;now wait for the event we should terminate at.
  129.     move.l    _AbsExecBase,a6        ;point to the system again
  130. loop:
  131.     move.l    CurrentWindow,a0    ;get the IDCMP port address and Wait on
  132.     move.l    WD_USERPORT(a0),a0    ;  it
  133.     push    a0            ;save the port address
  134.     callsys    WaitPort
  135.     pop    a0            ;get the message
  136.     callsys    GetMsg
  137.     move.l    d0,a1            ;message address to A1
  138.     move.l    IM_CLASS(a1),d4        ;save the event class in D4
  139.     callsys    ReplyMsg        ;reply the message
  140. ;termination test -- change it to any other IDCMP event, just be sure that your
  141. ;  IDCMP flags are set properly
  142.     cmp.l    #CLOSEWINDOW,d4        ;should we terminate now?
  143.     bne    loop            ;loop if not
  144.  
  145.     move.l    _IntuitionBase,a6    ;be sure to do next through Intuition
  146.  
  147. ;detach the menu if present
  148.     ifd MenuList
  149.     move.l    CurrentWindow,a0    ;window address to A0
  150.     callsys    ClearMenuStrip
  151.     endc
  152.  
  153.     move.l    CurrentWindow,a0    ;close the window
  154.     callsys    CloseWindow
  155.  
  156. ************    PROGRAM EXIT
  157. Exit:
  158.     move.l    _AbsExecBase,a6
  159.     move.l    _IntuitionBase,a1    ;close Intuition
  160.     callsys    CloseLibrary
  161. FatalExit:
  162.     move.l    ReturnMsg,d0        ;reply to any WorkBench message
  163.     beq    1$            ;jump if none
  164.     move.l    a1,d0            ;point with this here register
  165.     callsys    ReplyMsg        ;Reply the message
  166. 1$:
  167.     moveq    #0,d0            ;no error code returned
  168.     move.l    InitialSP,sp        ;return to the caller
  169.     rts
  170.  
  171.     end
  172.